/**
 * 
 */
package com.manthano.util.event.queue;

import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.Session;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

/**
 * EventQueueManager is used to handle send and receive MultiEventObject to
 * queue it creates one thread for each queue to monitor queue
 * 
 * @author Dell
 */
public class EventQueuePublisher
{
	private String				queueName			= null;
	private Queue				queue				= null;
	@SuppressWarnings("unused")
	private ConnectionFactory	connectionFactory	= null;
	private JmsTemplate			jmsTemplate			= null;

	/**
	 * <pre>
	 * </pre>
	 * 
	 * @param queue
	 * @param connectionFactory
	 * @throws JMSException
	 */
	public EventQueuePublisher(ConnectionFactory connectionFactory, Queue queue) throws JMSException
	{
		this.connectionFactory = connectionFactory;
		this.queue = queue;
		jmsTemplate = new JmsTemplate(connectionFactory);
		jmsTemplate.setSessionTransacted(true);
	}

	/**
	 * @param multiEventObject
	 * @throws JMSException
	 */
	public void publishEvent(final MultiEventObject multiEventObject) throws JMSException
	{

		this.jmsTemplate.send(this.queue, new MessageCreator()
		{
			public Message createMessage(Session session) throws JMSException
			{
				return session.createObjectMessage(multiEventObject);
			}
		});
	}

	/**
	 * @return the queueName
	 */
	public String getQueueName()
	{
		return queueName;
	}
}
